#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 19-6-25 下午11:45
# @Author  : Tom
# @Site    : 
# @File    : category.py
# @Software: PyCharm
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from goods.models import SPUSpecification, GoodsChannel, GoodsCategory, GoodsChannelGroup
from meiduo_admin.serilizers import CategoryGoodsSerilizer, GoodsCategorySerilizer, GoodsChannelGroupSerilizer
from meiduo_admin.utils import PageNumber_User


# sku的增删查改
class GoodsChannelView(ModelViewSet):
    # 添加序列化器和查询集
    serializer_class = CategoryGoodsSerilizer
    queryset = GoodsChannel.objects.all()
    # 指定分页类
    pagination_class = PageNumber_User
    permission_classes = [IsAdminUser, ]

    # 获取频道组
    def CategoryTypeView(self, reuqest):
        categorytype = GoodsChannelGroup.objects.all()
        ser = GoodsChannelGroupSerilizer(categorytype, many=True)
        return Response(ser.data)

    # 获取一级分类
    def categoriesView(self, reuqest):
        goodscat = GoodsCategory.objects.filter(parent=None)
        ser = GoodsCategorySerilizer(goodscat, many=True)
        return Response(ser.data)
